<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\BaseController;
use App\Models\UserExtend;
use Illuminate\Http\Request;

class LbsController extends BaseController
{

    public function city(Request $request) {
        $this->validate($request, [
            'longitude' => 'required',
            'latitude' => 'required'
        ]);
        $input = $request->input();
        $city = get_city_by_position($input);
        $user_id = $this->getUserId();
        if ($user_id) {
            UserExtend::where('user_id', $user_id)->update([
                'longitude' => $input['longitude'],
                'latitude' => $input['latitude'],
                'city' => $city
            ]);
        }

        return $this->success(['city' => $city]);
    }
}

